package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.api.Result;
import com.atguigu.springcloud.service.PaymentFuseService;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : wenchao.long
 * @date : Created in 2020/12/15 8:25 周二
 * @description :
 */
@RestController
@Slf4j
@RequestMapping("/payment")
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Autowired
    private PaymentFuseService paymentFuseService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/hystrix/ok/{id}")
    public Result<String> paymentInfo(@PathVariable("id") Integer id) {
        String result = paymentService.paymentInfo(id);
        log.info("===========result" + result + serverPort);
        return Result.data(result);
    }

    @GetMapping("/hystrix/timeout/{id}")
    public Result<String> paymentInfoTimeout(@PathVariable("id") Integer id) {
        String result = paymentService.paymentInfoTimeout(id);
        log.info("===========result" + result + "timeout");
        return Result.data(result);
    }

    @GetMapping("/fuse/{id}")
    public Result<String> paymentFuse(@PathVariable("id") Integer id) {
        String result = paymentFuseService.paymentCircuitBreaker(id);
        return Result.data(result);
    }
}
